package trad
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.geom.Point;
	
	public class SimpleTrad extends Sprite
	{
		private var start:Point = new Point(100, 100); // 从 100, 100 
		private var dest:Point = new Point(200, 150); // 移动到 200, 150
		private var totalFrames:int = 120; // 持续 30 帧
		private var currentFrame:int = 0; // 当前帧
		private var holder:Sprite = new Sprite();
		public function SimpleTrad()
		{
			
			this.addChild(holder);
			holder.graphics.lineStyle(1, 0);
			holder.graphics.moveTo(start.x, start.y);
			this.addEventListener(Event.ENTER_FRAME,onEnterFrame);
		}
		
		
		
		public function onEnterFrame(event:Event):void {
			if (currentFrame < totalFrames) {
				var x = linear(start.x, dest.x, 0, currentFrame, totalFrames);
				var y = linear(start.y, dest.y, 0, currentFrame, totalFrames);
				holder.graphics.lineTo(x, y);
				currentFrame++;
			} else {
				currentFrame = 0;
			}
		}
		// 传说中的缓动函数...
		function linear (propStart, propDest, timeStart, timeNow, timeDest) {
			var t = timeNow - timeStart;  // 当前时间
			var b = propStart;             // 起始值
			var c = propDest - propStart; // 距离目标还有多少
			var d = timeDest - timeStart; // 持续时间
			return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
			// 这段换成 return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; 的话就是缓冲画线了.
		}
	}
}